package com.fr.report.core;

import com.fr.base.FCloneable;
import com.fr.report.Cell;
import com.fr.report.CellCase;
import com.fr.report.DefaultCellCase;
import java.util.Iterator;
import java.util.NoSuchElementException;

public class SupportAddCellCaseContainer extends DefaultCellCase
{
  private static final long serialVersionUID = 7361398637897197787L;
  private CellCase packee;

  public static SupportAddCellCaseContainer pack(CellCase paramCellCase)
  {
    return new SupportAddCellCaseContainer(paramCellCase);
  }

  private SupportAddCellCaseContainer(CellCase paramCellCase)
  {
    this.packee = paramCellCase;
  }

  public void add(Cell paramCell, boolean paramBoolean)
  {
    if (paramCell == null)
      return;
    int i = paramCell.getRow();
    int j = paramCell.getRowSpan();
    int k = paramCell.getColumn();
    int l = paramCell.getColumnSpan();
    if ((i < 0) || (j <= 0) || (k < 0) || (l <= 0))
      return;
    if (this.packee.intersect(k, i, l, j).hasNext())
      throw new UnsupportedOperationException();
    super.add(paramCell, paramBoolean);
  }

  public Iterator cellIterator()
  {
    return new ContainerCellIterator(this, this.packee.cellIterator(), super.cellIterator());
  }

  public Cell get(int paramInt1, int paramInt2)
  {
    if ((paramInt1 < 0) || (paramInt2 < 0) || (paramInt1 > getColumnCount()) || (paramInt2 > getRowCount()))
      throw new IndexOutOfBoundsException();
    Cell localCell = null;
    try
    {
      localCell = this.packee.get(paramInt1, paramInt2);
      if (localCell == null)
        localCell = super.get(paramInt1, paramInt2);
    }
    catch (IndexOutOfBoundsException localIndexOutOfBoundsException)
    {
    }
    return localCell;
  }

  public Iterator getColumn(int paramInt)
  {
    return new ContainerCellIterator(this, this.packee.getColumn(paramInt), super.getColumn(paramInt));
  }

  public int getColumnCount()
  {
    return Math.max(this.packee.getColumnCount(), super.getColumnCount());
  }

  public Iterator getRow(int paramInt)
  {
    return new ContainerCellIterator(this, this.packee.getRow(paramInt), super.getRow(paramInt));
  }

  public int getRowCount()
  {
    return Math.max(this.packee.getRowCount(), super.getRowCount());
  }

  public Iterator intersect(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    return new ContainerCellIterator(this, this.packee.intersect(paramInt1, paramInt2, paramInt3, paramInt4), super.intersect(paramInt1, paramInt2, paramInt3, paramInt4));
  }

  public void recalculate()
  {
    this.packee.recalculate();
    super.recalculate();
  }

  public void releaseCache()
  {
    this.packee.releaseCache();
    super.releaseCache();
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    SupportAddCellCaseContainer localSupportAddCellCaseContainer = (SupportAddCellCaseContainer)super.clone();
    localSupportAddCellCaseContainer.packee = ((CellCase)this.packee.clone());
    return localSupportAddCellCaseContainer;
  }

  public void clear()
  {
    throw new UnsupportedOperationException();
  }

  public void insertColumn(int paramInt)
  {
    throw new UnsupportedOperationException();
  }

  public void insertRow(int paramInt)
  {
    throw new UnsupportedOperationException();
  }

  public Cell removeCell(int paramInt1, int paramInt2)
  {
    throw new UnsupportedOperationException();
  }

  public int removeColumn(int paramInt)
  {
    throw new UnsupportedOperationException();
  }

  public int removeRow(int paramInt)
  {
    throw new UnsupportedOperationException();
  }

  public void toCache(int paramInt1, int paramInt2, boolean paramBoolean)
  {
    throw new UnsupportedOperationException();
  }

  private class ContainerCellIterator
    implements Iterator
  {
    private Iterator packeei;
    private Iterator superi;
    private Cell packee_next;
    private Cell super_next;
    private final SupportAddCellCaseContainer this$0;

    ContainerCellIterator(, Iterator paramIterator1, Iterator paramIterator2)
    {
      this.this$0 = paramSupportAddCellCaseContainer;
      this.packee_next = null;
      this.super_next = null;
      this.packeei = paramIterator1;
      this.superi = paramIterator2;
      findPackeeNext();
      findSuperNext();
    }

    public boolean hasNext()
    {
      return ((this.packee_next != null) || (this.super_next != null));
    }

    public Object next()
    {
      Cell localCell;
      if (!(hasNext()))
        throw new NoSuchElementException("At last element");
      if (this.packee_next == null)
        localCell = this.super_next;
      else if (this.super_next == null)
        localCell = this.packee_next;
      else if (this.packee_next.getRow() == this.super_next.getRow())
        if (this.packee_next.getColumn() <= this.super_next.getColumn())
          localCell = this.packee_next;
        else
          localCell = this.super_next;
      else if (this.packee_next.getRow() < this.super_next.getRow())
        localCell = this.packee_next;
      else
        localCell = this.super_next;
      if (localCell == this.packee_next)
        findPackeeNext();
      else
        findSuperNext();
      return localCell;
    }

    private void findPackeeNext()
    {
      if (this.packeei.hasNext())
        this.packee_next = ((Cell)this.packeei.next());
      else
        this.packee_next = null;
    }

    private void findSuperNext()
    {
      if (this.superi.hasNext())
        this.super_next = ((Cell)this.superi.next());
      else
        this.super_next = null;
    }

    public void remove()
    {
      throw new UnsupportedOperationException();
    }
  }
}